package mfuny.ggongal.admin.report;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import mfuny.ggongal.admin.Server;
import mfuny.ggongal.admin.etc.Module;

import org.springframework.web.servlet.ModelAndView;

import com.ibatis.sqlmap.client.SqlMapClient;

public class ReportService {
	
	SqlMapClient sqlMapper;
	ModelAndView mav;
	
	public ReportService() throws Exception {
		sqlMapper = Server.getSqlMapper();
		mav = new ModelAndView();
	}
	
	//월별 리포트 페이지.
	public ModelAndView tempDayReportForm() {
		mav.clear();
		mav.setViewName("/reports/tempDayReportForm.ga");
		return mav;
	}
	
	//월별 리포트 결과.
	@SuppressWarnings("unchecked")
	public ModelAndView tempDayReport(String days) {
		HashMap<String, Object> result_usersCount = new HashMap<String, Object>();
		List<HashMap<String, Object>> result_dayReport = new ArrayList<HashMap<String, Object>>();
		
		try {
			//회원 정보 (총 가입자, 총 탈퇴자, 해당월 가입자, 해당월 탈퇴자)
			result_usersCount = (HashMap<String, Object>)sqlMapper.queryForObject("report_getUsersCount", days);
			
			//일별 꽁모으기, 경품게임 참여자 ( PV, UV )
//			HashMap<String, Object> paramMap = new HashMap<String, Object>();
//			paramMap.put("days", days);
//			paramMap.put("count", Module.getLastDay(Module.strToDate(days)));
			result_dayReport = sqlMapper.queryForList("report_getDayReport2", days);
			
		} catch ( Exception e ) {
			e.printStackTrace();
		}
		
		mav.clear();
		mav.addObject("result_usersCount", result_usersCount);
		mav.addObject("result_dayReport", result_dayReport);
		mav.setViewName("/reports/tempDayReport");
		
		return mav;
	}
}
